﻿
###TRIGGER LIST

# has_strong_religious_conviction_trigger
# is_christian_trigger

###DOCTRINE BASED###
# is_weak_claimant_due_to_gender_trigger
# can_be_combatant_based_on_gender_trigger
# can_be_clergy_due_to_gender_trigger
# faith_is_aniconic_trigger
# relation_with_character_is_incestuous_in_faith_trigger 	- Relation would be shunned in faith
# relation_with_character_is_incestuous_in_my_faith_trigger 			- Relation would be shunned in the faith of character you use trigger in
# relation_with_character_is_incestuous_in_my_or_lieges_faith_trigger - Relation would be shunned in the faith of the character you use trigger in or their liege's faith
# faith_allows_marriage_consanguinity_trigger
# relation_with_character_is_sodomy_in_faith_trigger
# relation_with_character_is_sodomy_trigger
# relation_with_character_is_sodomy_in_my_or_lieges_faith_trigger
# trait_is_shunned_in_faith_trigger
# trait_is_criminal_in_faith_trigger
# trait_is_shunned_or_criminal_in_my_or_lieges_faith_trigger
# has_negative_attitude_towards_trait_trigger
# secret_is_shunned_in_faith_trigger
# secret_is_criminal_in_faith_trigger
# secret_is_shunned_or_criminal_in_my_or_lieges_faith_trigger
# religion_has_angels_trigger
# highgod_is_passive_trigger
# highgod_is_active_trigger
# is_reincarnation_trigger
# holy_order_1000_request_target_trigger 		- Is this ruler a valid target for a holy order to request land from?

###HERESY TRIGGERS###
# is_valid_heresiarch

###RELIGIOUS INTERACTIONS###
# can_take_religious_vows_trigger


# CHECK A NUMBER OF RELIGION-RELATED CONDITIONS TO DETERMINE HOW STRONG OF A BELIEVER THEY SEEM TO BE
has_strong_religious_conviction_trigger = {
	NOR = {
		has_trait = cynical
		has_trait = excommunicated
	}
	OR = {
		has_trait = zealous
		has_trait = pilgrim
		has_trait = devoted
		has_trait = sayyid
		has_trait = saoshyant
		has_trait = savior
		has_trait = divine_blood
		has_trait = blood_of_prophet
		has_trait = faith_warrior
		has_trait = saint
	}
}

is_christian_trigger = {
	OR = {
		faith = { religion_tag = christianity_religion }
	}
}

# Not-non-XYZ triggers allow us to check for specific historical faiths whilst still defaulting to something positive for variant faiths.
## E.g., looking to see if something would only be of interest to Catholics, but if we're dealing with a player-made heresy, still return true. This way mechanics will default to on rather than off (still likely to result in weird GHWs, but at least less random ones).
not_non_catholic_standard_christian_faith_trigger = {
	NOR = {
		this = faith:orthodox
		this = faith:iconoclast
		this = faith:coptic
		this = faith:armenian_apostolic
	}
}

not_non_orthodox_standard_christian_faith_trigger = {
	NOR = {
		this = faith:catholic
		this = faith:coptic
		this = faith:armenian_apostolic
	}
}

not_non_coptic_standard_christian_faith_trigger = {
	NOR = {
		this = faith:catholic
		this = faith:orthodox
		this = faith:iconoclast
		this = faith:armenian_apostolic
	}
}

not_non_armenian_standard_christian_faith_trigger = {
	NOR = {
		this = faith:catholic
		this = faith:orthodox
		this = faith:iconoclast
		this = faith:coptic
	}
}

is_weak_claimant_due_to_gender_trigger = {
	OR = {
		AND = {
			$FAITH$ = { has_doctrine_parameter = female_claims_are_weak }
			$CHARACTER$ = { is_female = yes }
		}
		AND = {
			$FAITH$ = { has_doctrine_parameter = male_claims_are_weak }
			$CHARACTER$ = { is_male = yes }
		}
	}
}

can_be_combatant_based_on_gender_trigger = {
	custom_description = {
		text = "can_be_combatant_based_on_gender"
		object = this
		subject = $ARMY_OWNER$
		# Priests only fight if faith has war priests
		trigger_if = {
			limit = {
				OR = {
					has_trait = devoted
					is_clergy = yes
				}
			}
			OR = {
				faith = { has_doctrine_parameter = clergy_can_fight }
				culture = { has_cultural_parameter = culture_clergy_can_fight }
				AND = {
					$ARMY_OWNER$.culture = {
						has_cultural_parameter = high_prowess_ignores_knight_restrictions
					}
					prowess >= 10
				}
			}
		}
		OR = {
			trigger_if = { # Has the Royal Court and thus can modify pillars
				limit = {
					has_dlc_feature = diverge_culture # Can modify pillars
				}
				OR = {
					$ARMY_OWNER$ = { culture = { has_cultural_parameter = martial_custom_equal_combatant } }
					AND = {
						$ARMY_OWNER$ = { culture = { has_cultural_parameter = martial_custom_male_only_combatant } }
						is_male = yes
					}
					AND = {
						$ARMY_OWNER$ = { culture = { has_cultural_parameter = martial_custom_female_only_combatant } }
						is_female = yes
					}
				}
				
			}
			trigger_else = { # Does not have the Royal Court and thus combatant is governed by faith
				OR = {
					$ARMY_OWNER$ = { faith = { has_doctrine_parameter = combatant_can_be_either_gender_if_no_roco } }
					AND = {
						$ARMY_OWNER$ = { faith = { has_doctrine_parameter = combatant_must_be_male_if_no_roco } }
						is_male = yes
					}
					AND = {
						$ARMY_OWNER$ = { faith = { has_doctrine_parameter = combatant_must_be_female_if_no_roco } }
						is_female = yes
					}
				}
			}
			AND = {
				$ARMY_OWNER$ = {
					culture = { has_cultural_parameter = has_access_to_shieldmaidens }
				}
				# No need to gender diversify this: if they're a right-gender shieldperson of the culture, then they've already got permission to fight from the previous AND conditions.
				has_trait = shieldmaiden
			}
			# Event-based special exceptions
			OR = {
				has_character_modifier = ignores_gender_army_rules
				has_character_modifier = mpo_destined_leader_modifier
			}
			AND = {
				$ARMY_OWNER$ = { culture = { has_cultural_parameter = high_prowess_ignores_knight_restrictions } }
				NOT = { $ARMY_OWNER$ = { culture = { has_cultural_parameter = minimum_prowess_for_knights } } }
				prowess >= 10
			}
			AND = {
				$ARMY_OWNER$ = {
					culture = {
						has_cultural_parameter = high_prowess_ignores_knight_restrictions
						has_cultural_parameter = minimum_prowess_for_knights
					}
				}
				prowess >= 12
			}

			# Shogunate
			has_trait = female_commander
		}
	}
}

can_be_clergy_due_to_gender_trigger = {
	OR = {
		AND = {
			faith = { has_doctrine_parameter = clergy_must_be_female }
			is_female = yes
		}
		AND = {
			faith = { has_doctrine_parameter = clergy_must_be_male }
			is_male = yes
		}
		faith = { has_doctrine_parameter = clergy_can_be_either_gender }
	}
}

is_wrong_gender_in_faith_trigger = {
	OR = {
		AND = {
			is_female = yes
			$FAITH$ = { has_doctrine_parameter = male_dominated_law }
		}
		AND = {
			is_male = yes
			$FAITH$ = { has_doctrine_parameter = female_dominated_law }
		}
	}
}

faith_is_aniconic_trigger = {
	faith = {
		OR = {	
			religion = religion:islam_religion
			has_doctrine = tenet_aniconism
		}
	}
}

#Needs CHARACTER and FAITH
relation_with_character_is_incestuous_in_faith_trigger = {
	OR = {
		#doctrine_consanguinity_restricted; absolutely no family business 
		AND = {
			$FAITH$ = { has_doctrine = doctrine_consanguinity_restricted }
			is_close_or_extended_family_of = $CHARACTER$ #[parents, children, siblings, grandparents, grandchildren, cousins, uncles, aunts, nephews, nieces]
		}
		#doctrine_consanguinity_cousins; the only acceptable incest is with your cousin
		AND = {
			$FAITH$ = { has_doctrine = doctrine_consanguinity_cousins }
			OR = {
	            is_close_family_of = $CHARACTER$ #[parents, children, siblings, grandparents, grandchildren]
	            is_uncle_or_aunt_of = $CHARACTER$
	            is_nibling_of = $CHARACTER$
	        }
		}
		#doctrine_consanguinity_aunt_nephew_and_uncle_niece; extended family is ok
		AND = {
			$FAITH$ = { has_doctrine = doctrine_consanguinity_aunt_nephew_and_uncle_niece }	
			is_close_family_of = $CHARACTER$
		}
		#doctrine_consanguinity_unrestricted; all forms of incest is acceptable
	}	
}

#Note: only checks from the viewpoint of current scope. Needs CHARACTER
relation_with_character_is_incestuous_in_my_faith_trigger = {
	faith = { save_temporary_scope_as = my_faith }
	relation_with_character_is_incestuous_in_faith_trigger = { CHARACTER = $CHARACTER$ FAITH = scope:my_faith }
}

relation_with_character_is_incestuous_in_my_or_lieges_faith_trigger = {
	OR = {
		AND = {
			faith = { #My faith doesn't approve
				save_temporary_scope_as = check_faith
			}
			relation_with_character_is_incestuous_in_faith_trigger = { CHARACTER = $CHARACTER$ FAITH = scope:check_faith }
		}
		AND = { #Liege's faith doesn't approve
			exists = liege
			liege = {
				faith = {
					save_temporary_scope_as = check_faith
				}
			}
			relation_with_character_is_incestuous_in_faith_trigger = { CHARACTER = $CHARACTER$ FAITH = scope:check_faith }
		}
	}
}

#Needs CHARACTER_1 and CHARACTER_2
faith_allows_marriage_consanguinity_trigger = {
	save_temporary_scope_as = consanguinity_faith

	NOT = {
		$CHARACTER_1$ = {
			relation_with_character_is_incestuous_in_faith_trigger = {
				CHARACTER = $CHARACTER_2$
				FAITH = scope:consanguinity_faith
			}
		}
	}
}
relation_between_characters_is_sodomy_in_my_faith_trigger = {
	$CHARACTER_1$ = { is_male = yes }
	$CHARACTER_2$ = { is_male = yes }
	faith = { 
		OR = {
			has_doctrine_parameter = homosexuality_shunned 
			has_doctrine_parameter = homosexuality_illegal
		}
	}
}

relation_with_character_is_sodomy_in_faith_trigger = {
	is_male = yes
	$CHARACTER$ = { is_male = yes }
	$FAITH$ = {
		OR = {
			has_doctrine_parameter = homosexuality_shunned
			has_doctrine_parameter = homosexuality_illegal
		}
	}
}

#Note: only checks from the viewpoint of current scope. Needs CHARACTER
relation_with_character_is_sodomy_trigger = {
	faith = { save_temporary_scope_as = my_faith }
	relation_with_character_is_sodomy_in_faith_trigger = {
		CHARACTER = $CHARACTER$
		FAITH = scope:my_faith
	}
}

relation_with_character_is_sodomy_in_my_or_lieges_faith_trigger = {
	OR = {
		AND = {
			faith = { #My faith doesn't approve
				save_temporary_scope_as = check_faith
			}
			relation_with_character_is_sodomy_in_faith_trigger = { CHARACTER = $CHARACTER$ FAITH = scope:check_faith }
		}
		AND = { #Liege's faith doesn't approve
			exists = liege
			liege = {
				faith = {
					save_temporary_scope_as = check_faith
				}
			}
			relation_with_character_is_sodomy_in_faith_trigger = { CHARACTER = $CHARACTER$ FAITH = scope:check_faith }
		}
	}
}

murdering_character_is_kinslaying_in_faith_trigger = {
	OR = {
		is_close_or_extended_family_of = $CHARACTER$
		dynasty = $CHARACTER$.dynasty
	}
	$FAITH$ = { NOT = { has_doctrine = doctrine_kinslaying_accepted } }
}

murdering_character_is_kinslaying_in_my_or_same_dynasty_lieges_faith_trigger = {
	save_temporary_scope_as = kinslayer_me
	faith = {
		save_temporary_scope_as = check_faith
	}
	trigger_if = {
		limit = {
			exists = liege
			liege = { dynasty = scope:kinslayer_me.dynasty }
		}
		liege = {
			faith = {
				save_temporary_scope_as = check_faith_liege
			}
		}
	}
	OR = {
		murdering_character_is_kinslaying_in_faith_trigger = { CHARACTER = $CHARACTER$ FAITH = scope:check_faith } #My faith doesn't approve
		AND = { #Liege's faith doesn't approve
			exists = liege
			liege = { dynasty = scope:kinslayer_me.dynasty }
			murdering_character_is_kinslaying_in_faith_trigger = { CHARACTER = $CHARACTER$ FAITH = scope:check_faith_liege }
		}
	}
}



trait_is_shunned_in_faith_trigger = {
	save_temporary_scope_value_as = {
		name = shunned_trait_check
		value = flag:$TRAIT$
	}
	OR = {
		#INCEST
		AND = {
			scope:shunned_trait_check = flag:incestuous
			$FAITH$ = { NOT = { has_doctrine_parameter = allows_unrestricted_marriage } }
		}
		#WITCH
		AND = {
			scope:shunned_trait_check = flag:witch	
			$FAITH$ = { has_doctrine_parameter = witchcraft_shunned }
		}
		#SODOMITE
		AND = {
			scope:shunned_trait_check = flag:sodomite
			$FAITH$ = { has_doctrine_parameter = homosexuality_shunned }
		}
		#DEVIANT
		AND = {
			scope:shunned_trait_check = flag:deviant
			$FAITH$ = { has_doctrine_parameter = deviancy_shunned }
		}
		#ADULTERER/FORNICATOR
		AND = {
			OR = {
				scope:shunned_trait_check = flag:adulterer
				scope:shunned_trait_check = flag:fornicator
			}
			OR = {
				AND = {
					$FAITH$ = { has_doctrine_parameter = adultery_female_shunned }
					$GENDER_CHARACTER$ = { is_female = yes }
				}
				AND = {
					$FAITH$ = { has_doctrine_parameter = adultery_male_shunned }
					$GENDER_CHARACTER$ = { is_male = yes }
				}
			}
		}
		#KINSLAYER
		AND = {
			OR = {
				scope:shunned_trait_check = flag:kinslayer_1
				scope:shunned_trait_check = flag:kinslayer_2
				scope:shunned_trait_check = flag:kinslayer_3
			}
			$FAITH$ = { has_doctrine_parameter = kinslaying_shunned }
		}
	}
}

trait_is_criminal_in_faith_trigger = {
	save_temporary_scope_value_as = {
		name = criminal_trait_check
		value = flag:$TRAIT$
	}
	OR = {
		#KINSLAYER
		AND = {
			OR = {
				scope:criminal_trait_check = flag:kinslayer_3
				scope:criminal_trait_check = flag:kinslayer_2
				scope:criminal_trait_check = flag:kinslayer_1
			}
			$FAITH$ = { has_doctrine_parameter = kinslaying_any_dynasty_member_crime }
		}
		AND = {
			OR = {
				scope:criminal_trait_check = flag:kinslayer_3
				scope:criminal_trait_check = flag:kinslayer_2
			}
			$FAITH$ = { has_doctrine_parameter = kinslaying_extended_family_crime }
		}
		AND = {
			scope:criminal_trait_check = flag:kinslayer_3
			$FAITH$ = { has_doctrine_parameter = kinslaying_close_kin_crime }
		}
		#WITCH
		AND = {
			scope:criminal_trait_check = flag:witch
			$FAITH$ = { has_doctrine_parameter = witchcraft_illegal }
		}
		#CANNIBAL
		AND = {
			scope:criminal_trait_check = flag:cannibal
			NOT = {
				$FAITH$ = { has_doctrine_parameter = cannibalism_legal }
			}
		}
		#SODOMITE
		AND = {
			scope:criminal_trait_check = flag:sodomite
			$FAITH$ = { has_doctrine_parameter = homosexuality_illegal }
		}
		#DEVIANT
		AND = {
			scope:criminal_trait_check = flag:deviant
			$FAITH$ = { has_doctrine_parameter = deviancy_illegal }
		}
		#INCEST
		AND = {
			scope:criminal_trait_check = flag:incestuous
			$FAITH$ = { NOT = { has_doctrine_parameter = consanguinity_unrestricted_incest } }
		}
		#ADULTERER/FORNICATOR
		AND = {
			OR = {
				scope:criminal_trait_check = flag:adulterer
				scope:criminal_trait_check = flag:fornicator
			}
			OR = {
				AND = {
					$FAITH$ = { has_doctrine_parameter = adultery_female_crime }
					$GENDER_CHARACTER$ = { is_female = yes }
				}
				AND = {
					$FAITH$ = { has_doctrine_parameter = adultery_male_crime }
					$GENDER_CHARACTER$ = { is_male = yes }
				}
			}
		}
	}	
}

scoped_trait_is_criminal_in_faith_trigger = {
	OR = {
		#KINSLAYER
		AND = {
			OR = {
				$TRAIT$ = trait:kinslayer_3
				$TRAIT$ = trait:kinslayer_2
				$TRAIT$ = trait:kinslayer_1
			}
			$FAITH$ = { has_doctrine_parameter = kinslaying_any_dynasty_member_crime }
		}
		AND = {
			OR = {
				$TRAIT$ = trait:kinslayer_3
				$TRAIT$ = trait:kinslayer_2
			}
			$FAITH$ = { has_doctrine_parameter = kinslaying_extended_family_crime }
		}
		AND = {
			$TRAIT$ = trait:kinslayer_3
			$FAITH$ = { has_doctrine_parameter = kinslaying_close_kin_crime }
		}
		#WITCH
		AND = {
			$TRAIT$ = trait:witch
			$FAITH$ = { has_doctrine_parameter = witchcraft_illegal }
		}
		#CANNIBAL
		AND = {
			$TRAIT$ = trait:cannibal
			NOT = {
				$FAITH$ = { has_doctrine_parameter = cannibalism_legal }
			}
		}
		#SODOMITE
		AND = {
			$TRAIT$ = trait:sodomite
			$FAITH$ = { has_doctrine_parameter = homosexuality_illegal }
		}
		#DEVIANT
		AND = {
			$TRAIT$ = trait:deviant
			$FAITH$ = { has_doctrine_parameter = deviancy_illegal }
		}
		#INCEST
		AND = {
			$TRAIT$ = trait:incestuous
			$FAITH$ = { NOT = { has_doctrine_parameter = consanguinity_unrestricted_incest } }
		}
		#ADULTERER/FORNICATOR
		AND = {
			OR = {
				$TRAIT$ = trait:adulterer
				$TRAIT$ = trait:fornicator
			}
			OR = {
				AND = {
					$FAITH$ = { has_doctrine_parameter = adultery_female_crime }
					$GENDER_CHARACTER$ = { is_female = yes }
				}
				AND = {
					$FAITH$ = { has_doctrine_parameter = adultery_male_crime }
					$GENDER_CHARACTER$ = { is_male = yes }
				}
			}
		}
	}	
}

trait_is_shunned_or_criminal_in_faith_trigger = {
	OR = {
		trait_is_shunned_in_faith_trigger = { TRAIT = $TRAIT$ FAITH = $FAITH$ GENDER_CHARACTER = $GENDER_CHARACTER$ }
		trait_is_criminal_in_faith_trigger = { TRAIT = $TRAIT$ FAITH = $FAITH$ GENDER_CHARACTER = $GENDER_CHARACTER$ }
	}
}

trait_is_shunned_or_criminal_in_my_or_lieges_faith_trigger = {
	OR = {
		AND = {
			faith = { #My faith doesn't approve
				save_temporary_scope_as = check_faith
			}
			trait_is_shunned_or_criminal_in_faith_trigger = { TRAIT = $TRAIT$ FAITH = scope:check_faith GENDER_CHARACTER = $GENDER_CHARACTER$ }
		}
		AND = { #Liege's faith doesn't approve
			exists = liege
			liege = {
				faith = {
					save_temporary_scope_as = check_faith
				}
			}
			trait_is_shunned_or_criminal_in_faith_trigger = { TRAIT = $TRAIT$ FAITH = scope:check_faith GENDER_CHARACTER = $GENDER_CHARACTER$ }
		}
	}
}

has_any_shunned_or_criminal_trait_in_faith_trigger = {
	$CHARACTER$ = {
		OR = {
			#KINSLAYER
			AND = {
				has_trait = kinslayer_3
				trait_is_shunned_or_criminal_in_faith_trigger = { TRAIT = kinslayer_3 FAITH = $FAITH$ GENDER_CHARACTER = $CHARACTER$ }
			}
			AND = {
				has_trait = kinslayer_2
				trait_is_shunned_or_criminal_in_faith_trigger = { TRAIT = kinslayer_2 FAITH = $FAITH$ GENDER_CHARACTER = $CHARACTER$ }
			}
			AND = {
				has_trait = kinslayer_1
				trait_is_shunned_or_criminal_in_faith_trigger = { TRAIT = kinslayer_1 FAITH = $FAITH$ GENDER_CHARACTER = $CHARACTER$ }
			}
			#WITCH
			AND = {
				has_trait = witch
				trait_is_shunned_or_criminal_in_faith_trigger = { TRAIT = witch FAITH = $FAITH$ GENDER_CHARACTER = $CHARACTER$ }
			}
			#CANNIBAL
			AND = {
				has_trait = cannibal
				trait_is_shunned_or_criminal_in_faith_trigger = { TRAIT = cannibal FAITH = $FAITH$ GENDER_CHARACTER = $CHARACTER$ }
			}
			#SODOMITE
			AND = {
				has_trait = sodomite
				trait_is_shunned_or_criminal_in_faith_trigger = { TRAIT = sodomite FAITH = $FAITH$ GENDER_CHARACTER = $CHARACTER$ }
			}
			#DEVIANT
			AND = {
				has_trait = deviant
				trait_is_shunned_or_criminal_in_faith_trigger = { TRAIT = deviant FAITH = $FAITH$ GENDER_CHARACTER = $CHARACTER$ }
			}
			AND = {
				has_trait = incestuous
				trait_is_shunned_or_criminal_in_faith_trigger = { TRAIT = incestuous FAITH = $FAITH$ GENDER_CHARACTER = $CHARACTER$ }
			}
			#ADULTERER/FORNICATOR
			AND = {
				has_trait = adulterer
				trait_is_shunned_or_criminal_in_faith_trigger = { TRAIT = adulterer FAITH = $FAITH$ GENDER_CHARACTER = $CHARACTER$ }
			}
			AND = {
				has_trait = fornicator
				trait_is_shunned_or_criminal_in_faith_trigger = { TRAIT = fornicator FAITH = $FAITH$ GENDER_CHARACTER = $CHARACTER$ }
			}
		}
	}
}

has_any_criminal_trait_in_faith_trigger = {
	$CHARACTER$ = {
		OR = {
			#KINSLAYER
			AND = {
				has_trait = kinslayer_3
				trait_is_criminal_in_faith_trigger = { TRAIT = kinslayer_3 FAITH = $FAITH$ GENDER_CHARACTER = $CHARACTER$ }
			}
			AND = {
				has_trait = kinslayer_2
				trait_is_criminal_in_faith_trigger = { TRAIT = kinslayer_2 FAITH = $FAITH$ GENDER_CHARACTER = $CHARACTER$ }
			}
			AND = {
				has_trait = kinslayer_1
				trait_is_criminal_in_faith_trigger = { TRAIT = kinslayer_1 FAITH = $FAITH$ GENDER_CHARACTER = $CHARACTER$ }
			}
			#WITCH
			AND = {
				has_trait = witch
				trait_is_criminal_in_faith_trigger = { TRAIT = witch FAITH = $FAITH$ GENDER_CHARACTER = $CHARACTER$ }
			}
			#CANNIBAL
			AND = {
				has_trait = cannibal
				trait_is_criminal_in_faith_trigger = { TRAIT = cannibal FAITH = $FAITH$ GENDER_CHARACTER = $CHARACTER$ }
			}
			#SODOMITE
			AND = {
				has_trait = sodomite
				trait_is_criminal_in_faith_trigger = { TRAIT = sodomite FAITH = $FAITH$ GENDER_CHARACTER = $CHARACTER$ }
			}
			#DEVIANT
			AND = {
				has_trait = deviant
				trait_is_criminal_in_faith_trigger = { TRAIT = deviant FAITH = $FAITH$ GENDER_CHARACTER = $CHARACTER$ }
			}
			AND = {
				has_trait = incestuous
				trait_is_criminal_in_faith_trigger = { TRAIT = incestuous FAITH = $FAITH$ GENDER_CHARACTER = $CHARACTER$ }
			}
			#ADULTERER/FORNICATOR
			AND = {
				has_trait = adulterer
				trait_is_criminal_in_faith_trigger = { TRAIT = adulterer FAITH = $FAITH$ GENDER_CHARACTER = $CHARACTER$ }
			}
			AND = {
				has_trait = fornicator
				trait_is_criminal_in_faith_trigger = { TRAIT = fornicator FAITH = $FAITH$ GENDER_CHARACTER = $CHARACTER$ }
			}
		}
	}
}

has_any_shunned_trait_in_faith_trigger = {
	$CHARACTER$ = {
		OR = {
			#KINSLAYER
			AND = {
				has_trait = kinslayer_3
				trait_isshunnedl_in_faith_trigger = { TRAIT = kinslayer_3 FAITH = $FAITH$ GENDER_CHARACTER = $CHARACTER$ }
			}
			AND = {
				has_trait = kinslayer_2
				trait_is_shunned_in_faith_trigger = { TRAIT = kinslayer_2 FAITH = $FAITH$ GENDER_CHARACTER = $CHARACTER$ }
			}
			AND = {
				has_trait = kinslayer_1
				trait_is_shunned_in_faith_trigger = { TRAIT = kinslayer_1 FAITH = $FAITH$ GENDER_CHARACTER = $CHARACTER$ }
			}
			#WITCH
			AND = {
				has_trait = witch
				trait_is_shunned_in_faith_trigger = { TRAIT = witch FAITH = $FAITH$ GENDER_CHARACTER = $CHARACTER$ }
			}
			#CANNIBAL
			AND = {
				has_trait = cannibal
				trait_is_shunned_in_faith_trigger = { TRAIT = cannibal FAITH = $FAITH$ GENDER_CHARACTER = $CHARACTER$ }
			}
			#SODOMITE
			AND = {
				has_trait = sodomite
				trait_is_shunned_in_faith_trigger = { TRAIT = sodomite FAITH = $FAITH$ GENDER_CHARACTER = $CHARACTER$ }
			}
			#DEVIANT
			AND = {
				has_trait = deviant
				trait_is_shunned_in_faith_trigger = { TRAIT = deviant FAITH = $FAITH$ GENDER_CHARACTER = $CHARACTER$ }
			}
			AND = {
				has_trait = incestuous
				trait_is_shunned_in_faith_trigger = { TRAIT = incestuous FAITH = $FAITH$ GENDER_CHARACTER = $CHARACTER$ }
			}
			#ADULTERER/FORNICATOR
			AND = {
				has_trait = adulterer
				trait_is_shunned_in_faith_trigger = { TRAIT = adulterer FAITH = $FAITH$ GENDER_CHARACTER = $CHARACTER$ }
			}
			AND = {
				has_trait = fornicator
				trait_is_shunned_in_faith_trigger = { TRAIT = fornicator FAITH = $FAITH$ GENDER_CHARACTER = $CHARACTER$ }
			}
		}
	}
}


has_negative_attitude_towards_trait_trigger = {
	save_temporary_scope_value_as = {
		name = negative_status_check
		value = flag:$TRAIT$
	}

	NOR = {
		has_trait = $TRAIT$
		#INCESTUOUS
		AND = {
			scope:negative_status_check = flag:incestuous
			any_secret = { secret_type = secret_incest }
		}
		#WITCH
		AND = {
			scope:negative_status_check = flag:witch
			any_secret = { secret_type = secret_witch }
		}
		#CANNIBAL
		AND = {
			scope:negative_status_check = flag:cannibal
			any_secret = { secret_type = secret_cannibal }
		}
		#SODOMITE
		AND = {
			scope:negative_status_check = flag:sodomite
			OR = {
				has_sexuality = homosexual
				has_sexuality = bisexual
			}
			any_secret = {
				secret_type = secret_homosexual
			}
		}
		#ADULTERER
		AND = {
			scope:negative_status_check = flag:adulterer
			OR = {
				has_trait = lustful
				AND = {
					is_married = yes
					any_relation = { type = lover NOT = { is_spouse_of = prev } }
				}
				any_relation = {
					type = lover
					is_married = yes
					NOT = { is_spouse_of = prev }
				}
			}
		}
		#FORNICATOR
		AND = {
			scope:negative_status_check = flag:fornicator
			OR = {
				has_trait = lustful
				any_relation = { type = lover always = yes }
			}
		}
	}

	faith = { save_temporary_scope_as = my_faith }
	OR = {
		trait_is_shunned_in_faith_trigger = { TRAIT = $TRAIT$ FAITH = scope:my_faith GENDER_CHARACTER = $GENDER_CHARACTER$ }
		trait_is_criminal_in_faith_trigger = { TRAIT = $TRAIT$ FAITH = scope:my_faith GENDER_CHARACTER = $GENDER_CHARACTER$ }
	}
}

has_followers_trigger = {
	OR = {
		num_character_followers >= 1
		num_county_followers >= 1
	}
}

secret_is_blackmailable_trigger = {
	OR = {
		secret_is_blackmailable_strong_hook_trigger = { TARGET = $TARGET$ }
		secret_is_blackmailable_weak_hook_trigger = { TARGET = $TARGET$ }
	}
}


###################
# Heresy Triggers #
###################

is_preferred_heresy = {
	is_valid_heresy = {
		ORIGIN_FAITH = $ORIGIN_FAITH$
		HERETICAL_FAITH = $HERETICAL_FAITH$
	}

	OR = {
		#If we're Chistian, pick a heretical faiths which is in the same regional group as our origin faith (i.e., Lollards for Catholics, Iconoclasts for Orthodox, etc.)
		AND = {
			religion_tag = christianity_religion
			OR = {
				faiths_are_in_western_christianity_group = { FAITH_1 = $ORIGIN_FAITH$ FAITH_2 = $HERETICAL_FAITH$ }
				faiths_are_in_orthodox_christianity_group = { FAITH_1 = $ORIGIN_FAITH$ FAITH_2 = $HERETICAL_FAITH$ }
				faiths_are_in_eastern_christianity_group = { FAITH_1 = $ORIGIN_FAITH$ FAITH_2 = $HERETICAL_FAITH$ }
			}
		}

		#If we're Muslim, we want to stay within our 'branch' of Islam:
		AND = {
			religion_tag = islam_religion
			OR = {
				faiths_are_in_sunni_islam_group = { FAITH_1 = $ORIGIN_FAITH$ FAITH_2 = $HERETICAL_FAITH$}
				faiths_are_in_shia_islam_group = { FAITH_1 = $ORIGIN_FAITH$ FAITH_2 = $HERETICAL_FAITH$}
				faiths_are_in_muhakkima_islam_group = { FAITH_1 = $ORIGIN_FAITH$ FAITH_2 = $HERETICAL_FAITH$}
			}
		}
		#If we're Zoroastrian, we don't want Sogdian faith in Armenia and vice versa 
		AND = {
			religion_tag = zoroastrianism_religion
			OR = {
				faiths_are_eastern_zoroastrian = { FAITH_1 = $ORIGIN_FAITH$ FAITH_2 = $HERETICAL_FAITH$}
				faiths_are_western_zoroastrian = { FAITH_1 = $ORIGIN_FAITH$ FAITH_2 = $HERETICAL_FAITH$}
			}
		}

		#Otherwise, we don't have any special preferences.
		AND = {
			NOT = {
				religion_tag = islam_religion
				religion_tag = christianity_religion
				religion_tag = zoroastrianism_religion
			}
		}
	}
}

is_valid_heresy = {
	#The origin faith can never be its own heresy.
	NOT = { $ORIGIN_FAITH$ = $HERETICAL_FAITH$ }
	#Must not be considered invalid
	invalid_for_heresy_events = no
	# A heretical faith can't be currently locked off via variable.
	$HERETICAL_FAITH$ = {
		NOR = {
			has_variable = block_conversion_till_decision_taken
			has_variable = block_conversion_till_nebulous_circumstances
		}
	}
	#Depending on the origin faith's religion/religion group, there may have additional requirements for a heresy to be considered valid.
	OR = {
		#For Christian Faiths, the origin and heretical faiths must not both be Ecumenical (excepting the faiths which aren't technically ecumenical).
		AND = {
			religion_tag = christianity_religion
			NAND = {
				$ORIGIN_FAITH$ = {
					has_doctrine = special_doctrine_ecumenical_christian
					OR = {
						this = faith:insular_celtic
						this = faith:bosnian_church
						this = faith:mozarabic_church
					}
				}
				$HERETICAL_FAITH$ = {
					has_doctrine = special_doctrine_ecumenical_christian
					OR = {
						this = faith:insular_celtic
						this = faith:bosnian_church
						this = faith:mozarabic_church
					}
				}
			}
		}
		#For Shinto Faiths, the origin and heretical faiths must not be the combination of Ikko-shu and Hokke-shu.
		AND = {
			religion_tag = shinto_religion
			NOR = {
				AND = {
					$ORIGIN_FAITH$ = faith:ikkoshu
					$HERETICAL_FAITH$ = faith:hokkeshu
				}
				AND = {
					$ORIGIN_FAITH$ = faith:hokkeshu
					$HERETICAL_FAITH$ = faith:ikkoshu
				}
			}
		}
		AND = { #FP3: for Zoroastrianism, Bedhin faiths are never heresies of each other 
			religion_tag = zoroastrianism_religion
			NAND = {
				$ORIGIN_FAITH$ = {
					has_doctrine = doctrine_major_branch_behdin
				}
				$HERETICAL_FAITH$ = {
					has_doctrine = doctrine_major_branch_behdin
				}
			}
		}
		#No special requirements for Muslims, Jews, or Yazidis
		religion_tag = islam_religion
		religion_tag = judaism_religion
		#Eastern Faiths can shift and spread amongst each other.
		AND = {
			OR = {
				religion_tag = buddhism_religion
				religion_tag = hinduism_religion
				religion_tag = jainism_religion
				religion_tag = dualism_religion
			}
		}
		#No special requirements for Pagan religions.
		has_doctrine = pagan_hostility_doctrine
	}
}

is_valid_heresiarch = {
	is_landed = yes
	faith = root
	OR = {
		highest_held_title_tier = tier_duchy
		highest_held_title_tier = tier_county
	}
	is_imprisoned = no
	is_capable_adult_ai = yes
	is_playable_character = yes
	is_landless_adventurer = no
	primary_title ?= {
		is_landless_type_title = no
		is_noble_family_title = no
	}
	exists = capital_county
	NOT = { has_trait = heresiarch }
	no_heretical_hof_faith_trigger = yes
	recently_converted_faith_trigger = no # As amusing as it may be, rulers shouldn't 'flip-flop' between Faiths, so we need to enforce a cooldown on heresy conversions.
}

no_heretical_hof_faith_trigger = { #Head of Faith shouldn't convert.
	OR = {
		NOT = { exists = root.religious_head }
		AND = {
			exists = root.religious_head
			NOT = { this = root.religious_head }
		}
	}
}

#Christian Heresy Groups
faiths_are_in_western_christianity_group = {
	OR = {
		$FAITH_1$ = faith:catholic
		$FAITH_1$ = faith:cathar
		$FAITH_1$ = faith:waldensian
		$FAITH_1$ = faith:lollard
		AND = {
			$FAITH_1$ = faith:insular_celtic
			scope:heretic_capital.title_province = { geographical_region = world_europe_west_britannia }
		}
		AND = {
			$FAITH_1$ = faith:mozarabic_church
			scope:heretic_capital.title_province = { geographical_region = world_europe_west_iberia }
		}
	}
	OR = {
		$FAITH_2$ = faith:catholic
		$FAITH_2$ = faith:cathar
		$FAITH_2$ = faith:waldensian
		$FAITH_2$ = faith:lollard
		$FAITH_2$ = faith:priscillianism
		AND = {
			$FAITH_2$ = faith:insular_celtic
			scope:heretic_capital.title_province = { geographical_region = world_europe_west_britannia }
		}
		AND = {
			$FAITH_2$ = faith:mozarabic_church
			scope:heretic_capital.title_province = { geographical_region = world_europe_west_iberia }
		}
	}
}

faiths_are_in_orthodox_christianity_group = {
	OR = {
		$FAITH_1$ = faith:orthodox
		$FAITH_1$ = faith:iconoclast
		$FAITH_1$ = faith:bogomilist
		$FAITH_1$ = faith:paulician
		AND = {
			$FAITH_1$ = faith:bosnian_church
			scope:heretic_capital.title_province = { geographical_region = world_europe_south_east }
		}
	}
	OR = {
		$FAITH_2$ = faith:orthodox
		$FAITH_2$ = faith:iconoclast
		$FAITH_2$ = faith:bogomilist
		$FAITH_2$ = faith:paulician
		$FAITH_2$ = faith:bosnian_church
		$FAITH_2$ = faith:cainitism
		AND = {
			$FAITH_1$ = faith:bosnian_church
			scope:heretic_capital.title_province = { geographical_region = world_europe_south_east }
		}
	}
}

faiths_are_in_eastern_christianity_group = {
	OR = {
		$FAITH_1$ = faith:coptic
		$FAITH_1$ = faith:armenian_apostolic
		$FAITH_1$ = faith:nestorian
		$FAITH_1$ = faith:messalian
		$FAITH_1$ = faith:paulician
	}
	OR = {
		$FAITH_2$ = faith:coptic
		$FAITH_2$ = faith:armenian_apostolic
		$FAITH_2$ = faith:nestorian
		$FAITH_2$ = faith:messalian
		$FAITH_2$ = faith:paulician
		$FAITH_2$ = faith:mandeaism
	}
}

faiths_are_shia_zandaqa_sub_group = {
	OR = {
		this = faith:quranist
		this = faith:qarmatian
		this = faith:ghulat
		this = faith:alawite
		this = faith:alevi
		this = faith:druze
	}
}

faiths_are_in_sunni_islam_group = {
	$FAITH_1$ = {
		has_doctrine = muhammad_succession_sunni_doctrine
	}
	$FAITH_2$ = {
		OR = {
			has_doctrine = muhammad_succession_sunni_doctrine
			has_doctrine = muhammad_succession_muhakkima_doctrine
			this = faith:sabianism
			this = faith:manichean
			this = faith:quranist
		}
	}
}

faiths_are_in_shia_islam_group = {
	$FAITH_1$ = {
		OR = {
			has_doctrine = muhammad_succession_shia_doctrine
			faiths_are_shia_zandaqa_sub_group = yes
		}
	}
	$FAITH_2$ = {
		OR = {
			has_doctrine = muhammad_succession_shia_doctrine
			has_doctrine = muhammad_succession_muhakkima_doctrine
			faiths_are_shia_zandaqa_sub_group = yes
			this = faith:valentinianism
			this = faith:sabianism
		}
	}
}

faiths_are_in_muhakkima_islam_group = {
	$FAITH_1$ = {
		has_doctrine = muhammad_succession_muhakkima_doctrine
	}
	$FAITH_2$ = {
		OR = {
			has_doctrine = muhammad_succession_muhakkima_doctrine
			this = faith:manichean
			this = faith:valentinianism
		}
	}
}

faiths_are_eastern_zoroastrian = { #FP3 update - so that Armenian faith (Arewordik) don't appear as a heresy in Sogdia
	OR = {
		$FAITH_1$ = faith:mazdayasna
		$FAITH_1$ = faith:khurmazta
		$FAITH_1$ = faith:gayomarthianism
		$FAITH_2$ = faith:zurvanism
		$FAITH_2$ = faith:mazdakism
		$FAITH_2$ = faith:khurramism
	}
	OR = {
		$FAITH_1$ = faith:mazdayasna
		$FAITH_1$ = faith:khurmazta
		$FAITH_1$ = faith:gayomarthianism
		$FAITH_2$ = faith:zurvanism
		$FAITH_2$ = faith:mazdakism
		$FAITH_2$ = faith:khurramism
	}
}

faiths_are_western_zoroastrian = { #FP3 update - so that Sogdian faith (Khurmazta) don't appear as a heresy in Armenia 
	OR = {
		$FAITH_1$ = faith:mazdayasna
		$FAITH_1$ = faith:gayomarthianism
		$FAITH_2$ = faith:zurvanism
		$FAITH_2$ = faith:mazdakism
		$FAITH_2$ = faith:khurramism
		$FAITH_2$ = faith:urartuism
	}
	OR = {
		$FAITH_1$ = faith:mazdayasna
		$FAITH_1$ = faith:gayomarthianism
		$FAITH_2$ = faith:zurvanism
		$FAITH_2$ = faith:mazdakism
		$FAITH_2$ = faith:khurramism
		$FAITH_2$ = faith:urartuism
	}
}

refusing_conversion_is_crime_trigger = {
	faith = {
		trigger_if = { # Only apply imprisonment reason if actor's faith is not the state faith
			limit = {
				$CHARACTER$ = {
					top_liege = { government_allows = state_faith }
					faith = $CHARACTER$.top_liege.primary_title.state_faith
				}
			}
			always = no
		}
		OR = {
			religion_tag = christianity_religion
			religion_tag = islam_religion
			religion_tag = judaism_religion
			religion_tag = zoroastrianism_religion
		}
		NOT = {
			faith_hostility_level = {
				target = $CHARACTER$.faith
				value <= faith_astray_level
			}
		}
	}
}

is_hostile_enough_for_holy_war_trigger = {
	faith_hostility_level = {
		target = $FAITH$
		value >= religious_cb_enabled_hostility_level
	}
}

barony_is_valid_for_holy_order_lease_trigger = {
	title_province = {
		OR = {
			has_holding_type = castle_holding
			has_holding_type = city_holding
		}
	}
	trigger_if = {
		limit = {
			holder.primary_title.tier != tier_barony
		}
		can_be_leased_out = yes
	}
	trigger_if = {
		limit = {
			NOT = { holder = $CHARACTER$ }
		}
		holder.primary_title.tier = tier_barony	
	}
	NOT = {
		is_leased_out = yes
	}
}

barony_is_valid_for_holy_order_lease_cancellation_trigger = {
	is_under_holy_order_lease = yes
	has_revokable_lease = yes
	lessee = {
		NOT = {
			has_strong_hook = prev.holder
		}
	}
}

religion_has_angels_trigger = {
	OR = {
		religion = religion:christianity_religion
		religion = religion:islam_religion
		religion = religion:zoroastrianism_religion
		religion = religion:dualism_religion
		religion = religion:judaism_religion
		religion = religion:yazidi_religion
	}
}

religion_has_circumcision_trigger = {
	OR = {
		religion = religion:islam_religion
		religion = religion:judaism_religion
	}
}

is_heretic_trigger = {
	$WHO$.faith.religion = $TARGET$.faith.religion
	$WHO$.faith = {
		faith_hostility_level = {
			target = $TARGET$.faith
			value >= religious_cb_enabled_hostility_level
		}
	}
}

is_heathen_trigger = {
	NOT = { $WHO$.faith.religion = $TARGET$.faith.religion }
	$TARGET$.faith = {
		has_doctrine = pagan_hostility_doctrine
	}
	$WHO$.faith = {
		faith_hostility_level = {
			target = $TARGET$.faith
			value >= religious_cb_enabled_hostility_level
		}
	}
}

is_infidel_trigger = {
	NOT = { $WHO$.faith.religion = $TARGET$.faith.religion }
	$TARGET$.faith = {
		NOT = { has_doctrine = pagan_hostility_doctrine }
	}
	$WHO$.faith = {
		faith_hostility_level = {
			target = $TARGET$.faith
			value >= religious_cb_enabled_hostility_level
		}
	}
}

valid_demand_conversion_conditions_trigger = {
	scope:recipient = { is_busy_in_events_localised = yes }
	scope:recipient = { NOT = { has_strong_hook = scope:actor } }
	scope:recipient = { NOT = { has_trait = devoted } }
	scope:recipient = { NOT = { has_trait = order_member } }
	scope:recipient = {
		NOT = { is_imprisoned_by = scope:actor }
	}
	scope:recipient = {
		NOT = { is_at_war_with = scope:actor }
	}
	scope:actor = {
		trigger_if = {
			limit = {
				government_has_flag = government_is_landless_adventurer
				scope:recipient = { is_courtier_of = scope:actor }
			}
			custom_tooltip = {
				text = valid_demand_conversion_conditions_trigger.tt.domicile_requires_shrine
				domicile = { has_domicile_parameter = camp_enable_conversion }
			}
		}
	}
	scope:actor = {
		NAND = {
			has_trait = nomadic_philosophy
			has_trait = zealous
		}
	}

	custom_description = {
		text = "is_head_of_religion"
		subject = scope:recipient
		NOT = { scope:recipient.faith.religious_head = scope:recipient }
	}

	custom_description = {
		text = "is_protected_via_contract"
		subject = scope:recipient
		NAND = { # Vassal Contract forbids meddling by liege
			exists = scope:recipient.liege
			scope:recipient.liege = scope:actor
			scope:recipient = {
				is_ruler = yes
				vassal_contract_has_flag = religiously_protected
			}
		}
	}
	
	trigger_if = {
		limit = {
			scope:recipient = {	
				AND = {
					has_variable = cannot_be_converted_by_value
					var:cannot_be_converted_by_value = scope:actor	
				}
			}
		}
		custom_tooltip = {
			text = promised_to_not_convert_character
			scope:recipient = {	
				NOR = {
					has_variable = cannot_be_converted_by_value
					var:cannot_be_converted_by_value = scope:actor
				}
			}
		}
	}

	custom_tooltip = {
		text = cannot_take_overt_hostile_actions_against_diarch.tt
		NOT = { scope:recipient ?= scope:actor.diarch }
	}
}

highgod_is_passive_trigger = {
	OR = {
		religion_tag = buddhism_religion
		religion_tag = jainism_religion
		religion_tag = taoism_religion
		religion_tag = west_african_roog_religion
		religion_tag = zunism_religion
	}
}

highgod_is_active_trigger = {
	highgod_is_passive_trigger = no
}


fertilitygod_is_active_trigger = {
	highgod_is_active_trigger = yes
}


###REINCARNATION###
can_become_reincarnation_trigger = {
	save_temporary_scope_as = reincarnated_child
	faith = {
		has_doctrine = tenet_reincarnation
	}
	any_parent = {
		is_playable_character = yes
		faith = scope:reincarnated_child.faith
	}
}

can_reincarnate_trigger = {
	is_alive = no
	OR = {
		has_trait = temperate
		has_trait = greedy
		has_trait = generous
		has_trait = diligent
		has_trait = calm
		has_trait = arrogant
		has_trait = humble
		has_trait = deceitful
		has_trait = honest
		has_trait = brave
		has_trait = gregarious
		has_trait = ambitious
		has_trait = just
		has_trait = zealous
		has_trait = compassionate
		has_trait = stubborn
		has_trait = forgiving
		has_trait = lunatic
		has_trait = dull
		has_trait = intellect_bad
		has_trait = shrewd
		has_trait = intellect_good
		has_trait = strong
		has_trait = physique_good
	}
}

is_reincarnation_trigger = {
	can_become_reincarnation_trigger = yes
	OR = {
		AND = {
			has_variable = reincarnation_of

		}

	}
}

# Used in faith scope, COUNT is number of faiths to at least have and CHARACTER is who must own them
num_realm_holy_sites_faithful_holders = {
	$CHARACTER$ = { save_temporary_scope_as = root_scope }
	trigger_if = {
		limit = {
			exists = $CHARACTER$.confederation
		}
		custom_description = {
			text = direct_realm_holy_sites_held_by_faithful_confederation
			subject = $CHARACTER$
			object = this
			value = 1
			any_holy_site = {
				county = {
					save_temporary_scope_as = current_holy_site
					is_holy_site_controlled_by = $CHARACTER$
					holder.faith = $CHARACTER$.faith
				}
			}
		}
	}
	custom_description = {
		text = number_realm_holy_sites_held_by_faithful
		subject = $CHARACTER$
		object = this
		value = $COUNT$
		any_holy_site = {
			count >= $COUNT$
			county = {
				save_temporary_scope_as = current_holy_site
				OR = {
					is_holy_site_controlled_by = $CHARACTER$
					$CHARACTER$.confederation ?= {
						any_confederation_member = {
							scope:current_holy_site = {
								is_holy_site_controlled_by = prev
							}
						}
					}
				}
				holder.faith = $CHARACTER$.faith
			}
		}
	}
}

### Head of Faith
can_create_temporal_head_of_faith_title_trigger = {
	num_realm_holy_sites_faithful_holders = {
		COUNT = holy_sites_to_create_temporal_head_of_faith
		CHARACTER = ROOT
	}
	root = { piety_level >= high_piety_level }
	trigger_if = {
		limit = {
			root = { is_independent_ruler = no }
		}
		custom_description = {
			text = cannot_create_hof_title_at_or_above_liege_tier
			root.liege.primary_title.tier > tier_duchy
		}
	}
}

can_create_spiritual_head_of_faith_title_trigger = {
    num_realm_holy_sites_faithful_holders = {
        COUNT = holy_sites_to_create_spiritual_head_of_faith
        CHARACTER = ROOT
    }
    root = { piety_level >= medium_piety_level }
    trigger_if = {
        limit = { has_doctrine = special_doctrine_not_allowed_to_hof }
        NOT = { has_doctrine = special_doctrine_not_allowed_to_hof }
    }
    NAND = {
        exists = religious_head
        has_doctrine_parameter = maintains_head_of_faith_on_creation
    }
}

# this = Person trying to create the title
can_afford_create_head_of_faith_title_cost_trigger = {
	trigger_if = {
		limit = {
			faith = {
				has_doctrine_parameter = temporal_head_of_faith
				OR = {
					has_doctrine = muhammad_succession_sunni_doctrine
					has_doctrine = muhammad_succession_shia_doctrine
				}
			}		
		}
		trigger_if = {
			limit = { NOT = { has_trait = sayyid } }
			piety >= massive_piety_value
		}
	}
	trigger_else_if = {
		limit = {
			faith = {
				has_doctrine_parameter = temporal_head_of_faith
			}
		}
		piety >= major_piety_value
	}
	trigger_else = {
		limit = {
			faith = {
				has_doctrine_parameter = spiritual_head_of_faith
			}
		}
		gold >= medium_gold_max_value
	}
}

# FAITH = The faith we are trying to make the head of faith title for
# this = Person trying to create the title
can_create_head_of_faith_title_trigger = {
	$FAITH$ = {
		trigger_if = {
			limit = {
				has_doctrine_parameter = spiritual_head_of_faith
			}
			can_create_spiritual_head_of_faith_title_trigger = yes
		}
		trigger_else_if = {
			limit = {
				has_doctrine_parameter = temporal_head_of_faith
			}
			can_create_temporal_head_of_faith_title_trigger = yes
		}
		trigger_else = {
			# We shouldn't hit this point, but if we do use the following as error messages.
			has_doctrine_parameter = spiritual_head_of_faith
			has_doctrine_parameter = temporal_head_of_faith
		}
	}
	can_afford_create_head_of_faith_title_cost_trigger = yes
}

can_perform_the_hajj_trigger = {
	faith.religion = religion:islam_religion
	faith = { has_doctrine_parameter = can_go_on_pilgrimage }
}

shared_faith_or_hof_trigger = {
	OR = {
		$ACTOR$.faith = $RECIPIENT$.faith
		AND = {
			exists = $ACTOR$.faith.religious_head
			exists = $RECIPIENT$.faith.religious_head
			$ACTOR$.faith.religious_head = $RECIPIENT$.faith.religious_head
		}
	}
}


###RELIGIOUS INTERACTIONS###
#Triggers that applies to both Monastery or Holy Order requirements
can_take_religious_vows_trigger = {
	can_take_religious_vows_disregard_marriage_trigger = yes
	
	#Do they have the "wrong" marriage type?
	NOR = {
		custom_description = {
			text = is_married_matrilineally
			subject = scope:recipient
			any_spouse = {
				is_female = yes
				matrilinear_marriage = yes
			}
		}
		custom_description = {
			text = is_married_patrilineally
			subject = scope:recipient
			any_spouse = {
				is_male = yes
				patrilinear_marriage = yes
			}
		}
		custom_description = {
			text = matrilinear_betrothal
			subject = scope:recipient
			exists = betrothed
			betrothed = {
				is_female = yes
				matrilinear_betrothal = yes
			}
		}
		custom_description = {
			text = patrilinear_betrothal
			subject = scope:recipient
			exists = betrothed
			betrothed = {
				is_male = yes
				patrilinear_betrothal = yes
			}
		}
	}
	bp2_valid_for_standard_interactions_trigger = yes
}

can_take_religious_vows_disregard_marriage_trigger = {
	is_available_ai = yes
	faith = scope:actor.faith
	is_ruler = no
	NOT = { has_trait = excommunicated }
	NOT = { has_character_flag = holy_order_member_requested_return_home }
}

does_religion_exist_in_world_region_trigger = { # The most efficient way I could think of to essentially do diplomatic range triggers on religions
	trigger_if = {
		limit = { location = { geographical_region = world_europe } } # Even though europe has many sub regions, it's overall size is small so no need to sub-divide!
		any_county_in_region = {
			region = world_europe
			faith.religion = $RELIGION$
		}
	}
	trigger_else_if = {
		limit = { location = { geographical_region = world_asia_minor } } # Maybe this should be grouped with both the one above and the one below...
		any_county_in_region = {
			region = world_asia_minor
			faith.religion = $RELIGION$
		}
	}
	trigger_else_if = {
		limit = { location = { geographical_region = world_middle_east } }
		any_county_in_region = {
			region = world_middle_east
			faith.religion = $RELIGION$
		}
	}
	trigger_else_if = {
		limit = {
			location = { geographical_region = world_india } }
		any_county_in_region = {
			region = world_india
			faith.religion = $RELIGION$
		}
	}
	trigger_else_if = {
		limit = { location = { geographical_region = world_africa } }
		any_county_in_region = {
			region = world_africa
			faith.religion = $RELIGION$
		}
	}
	trigger_else_if = {
		limit = { location = { geographical_region = world_steppe } }
		any_county_in_region = {
			region = world_steppe
			faith.religion = $RELIGION$
		}
	}
	trigger_else_if = { # We group two smaller world regions into one
		limit = {
			location = {
				OR = {
					geographical_region = world_tibet
					geographical_region = world_burma
				}
			}
		}
		OR = {
			any_county_in_region = {
				region = world_tibet
				faith.religion = $RELIGION$
			}
			any_county_in_region = {
				region = world_burma
				faith.religion = $RELIGION$
			}
		}
	}
	trigger_else = { always = no } # This should always go at the end of this scripted trigger
}

### HOLY ORDERS ###
holy_order_1000_holy_order_trigger = {
	title = {
		NOR = {
			has_variable = received_new_land
			has_variable = discarded_for_being_too_big
		}
	}
}

holy_order_1000_target_barony_trigger = {
	tier = tier_barony
	barony_is_valid_for_holy_order_lease_trigger = { CHARACTER = $CHARACTER$ }
	#Don't grab something that's held by a vassal player of the one receiving the event.
	trigger_if = {
		limit = {
			NOT = { holder = $CHARACTER$ }
		}
		holder = { is_ai = yes }
	}
}

holy_order_1000_request_target_trigger = {
	highest_held_title_tier >= tier_duchy
	is_landed_or_landless_administrative = yes
	faith = root
	is_available = yes
	NOR = {
		has_character_flag = holy_order_recently_requested_land
		has_character_flag = holy_order_recently_received_land
	}
	save_temporary_scope_as = ruler
	any_sub_realm_barony = {
		holy_order_1000_target_barony_trigger = { CHARACTER = scope:ruler }
	}
}

faith_dominant_gender_male_or_equal = {
	faith = {
		OR = {
			has_doctrine_parameter = male_dominated_law
			has_doctrine_parameter = gender_equal_law
		}
	}
}

faith_dominant_gender_female_or_equal = {
	faith = {
		OR = {
			has_doctrine_parameter = female_dominated_law
			has_doctrine_parameter = gender_equal_law
		}
	}
}

is_theological_character_trigger = {
	OR = {
		has_trait = theologian
		has_trait = devoted
		has_trait = order_member
		AND = {
			is_playable_character = yes
			government_has_flag = government_is_theocracy
		}

	}	
}

would_be_sinful_adulterer_trigger = {
	is_married = yes
	trigger_if = {
		limit = { is_male = yes }
		NOT = {
			faith = { has_doctrine = doctrine_adultery_men_accepted }
		}
	}
	trigger_else = {
		NOT = {
			faith = { has_doctrine = doctrine_adultery_women_accepted }
		}
	}
}

has_tolerant_faith_or_culture_trigger = {
	OR = {
		faith = { has_doctrine = doctrine_pluralism_pluralistic }
		culture = { has_cultural_parameter = less_likely_to_force_conversion }
		has_trait = nomadic_philosophy
	}
}

is_mainstream_jewish_faith = {
	religion = religion:judaism_religion
	NOT = {
		this = faith:samaritan
		this = faith:haymanot
		this = faith:malabarism
		this = faith:kabarism
	}
}

is_unprotected_hostile_faith = { # Checks if the faith is at least hostile but not protected by a contract, used in a county scope
	faith = {
		faith_hostility_level = {
			target = prev.holder.top_liege.faith
			value >= 2
		}
	}
	holder = {
		NOT = { vassal_contract_has_flag = religiously_protected }
	}
	trigger_if = { # Does anyone in the hierarchy have religious protection?
		limit = {
			holder = {
				any_liege_or_above = {
					faith = prev.faith
				}
			}
		}
		holder = {
			any_liege_or_above = {
				NOT = { vassal_contract_has_flag = religiously_protected }
			}
		}
	}
}

### SYNCRETIC TRIGGERS ###

islam_or_syncretic_with_islam_trigger = {
	$CHARACTER$ = {
		faith = {
			OR = {
				religion = religion:islam_religion
				has_doctrine = tenet_islamic_syncretism
			}
		}
	}
}

judaism_or_syncretic_with_judaism_trigger = {
	$CHARACTER$ = {
		faith = {
			OR = {
				religion = religion:judaism_religion
				has_doctrine = tenet_jewish_syncretism
			}
		}
	}
}

christianity_or_syncretic_with_christianity_trigger = {
	$CHARACTER$ = {
		faith = {
			OR = {
				religion = religion:christianity_religion
				has_doctrine = tenet_christian_syncretism
			}
		}
	}
}

unreformed_or_syncretic_with_unreformed_trigger = {
	$CHARACTER$ = {
		faith = {
			OR = {
				religion = religion:unreformed_religion
				has_doctrine = tenet_unreformed_syncretism
			}
		}
	}
}

zoroastrian_or_syncretic_with_eastern_trigger = {
	$CHARACTER$ = {
		faith = {
			OR = {
				religion = religion:zoroastrianism_religion
				has_doctrine = tenet_eastern_syncretism
			}
		}
	}
}

#Used on faiths
is_dharmic_faith_trigger = {
	OR = {
		religion = religion:hinduism_religion
		religion = religion:buddhism_religion
		religion = religion:jainism_religion
	}
}

#Used on provinces
has_holy_building = {
	OR = {
		has_building_or_higher = holy_site_cathedral_01
		has_building_or_higher = holy_site_mosque_01
		has_building_or_higher = holy_site_pagan_grand_temple_01
		has_building_or_higher = holy_site_indian_grand_temple_01
		has_building_or_higher = holy_site_other_grand_temple_01
		has_building_or_higher = holy_site_cologne_cathedral_01
		has_building_or_higher = holy_site_canterbury_cathedral_01
		has_building_or_higher = temple_of_uppsala_01
		has_building_or_higher = lund_cathedral_01
		has_building_or_higher = notre_dame_01
		has_building_or_higher = holy_site_imam_ali_mosque_01
		has_building_or_higher = holy_site_great_mosque_of_mecca_01
		has_building_or_higher = holy_site_great_mosque_of_cordoba_01
		has_building_or_higher = holy_site_great_mosque_of_djenne_01
		has_building_or_higher = holy_site_great_mosque_of_samarra_01
		has_building_or_higher = holy_site_prophetic_mosque_01
		has_building_or_higher = brihadeeswarar_temple_01
		has_building_or_higher = shwedagon_pagoda_01
		has_building_or_higher = ananda_temple_01
		has_building_or_higher = the_friday_mosque_01
		has_building_or_higher = dome_of_the_rock_01
		has_building_or_higher = temple_in_jerusalem_01
		has_building_or_higher = cluny_abbey_01
		has_building_or_higher = damascus_mosque_01
		has_building_or_higher = jokhang_01
		has_building_or_higher = beta_giyorgis_01
		has_building_or_higher = holy_wisdom_01
		has_building_or_higher = duomo_florence_01
		has_building_or_higher = konark_temple_01
		has_building_or_higher = wawel_cathedral_01
		has_building_or_higher = vatapi_caves_01
	}
}

invalid_for_heresy_events = {
	OR = {
		this = faith:conversos
		this = faith:insular_celtic
		this = faith:bosnian_church
		this = faith:mozarabic_church
		this = faith:adamites
		this = faith:kabarism
	}
}
